import { devtools, persist, subscribeWithSelector } from "zustand/middleware";
import { create } from "zustand";
import { immer } from "zustand/middleware/immer";
import {getPermissions,getAllButtonPermissions} from '@/api'

const initialState = {
        permissionsList:[],
        buttonPermissionsList:[],
};

export const permissionsStore = create(
    immer(
        devtools(
            subscribeWithSelector(
                persist(() => initialState, {
                    name: "Permissions-store",
                })
            )
        )
    )
);

export const getPermissionsListFromApi=async()=>{
   const res=await getPermissions();
//    console.log(res);
   permissionsStore.setState((state)=>{
    state.permissionsList = res;
   })
}

export const getButtonPermissionsListFromApi=async()=>{
    const res=await getAllButtonPermissions();
    permissionsStore.setState((state)=>{
     state.buttonPermissionsList = res.docs;
    })
}
